{extend name="index/index" /}
{block name="main"}
<h3 onclick="show()">
    {if condition="$aaa"}
        <p class="glyphicon glyphicon-heart" id="shi" book_id="{$id}" style="color: crimson;display: block;"></p>
        <p class="glyphicon glyphicon-heart-empty" book_id="{$id}" id="kong" style="color: crimson;display: none;"></p>
    {else /}
        <p class="glyphicon glyphicon-heart" id="shi" book_id="{$id}" style="color: crimson;display: none;"></p>
        <p class="glyphicon glyphicon-heart-empty" book_id="{$id}" id="kong" style="color: crimson;display: block;"></p>
    {/if}
</h3>

<script>
    function show(){
        var shi = document.getElementById('shi');
        var kong = document.getElementById('kong');

        if (shi.style.display == 'none'){
            var book_id = $(kong).attr('book_id');
            if (confirm('确定加入书架？')){
                kong.style.display = 'none';
                shi.style.display = 'block';
                add_book(book_id);
            }

        } else{
            var book_id = $(shi).attr('book_id');
            if (confirm('确定移出书架？')){
                kong.style.display = 'block';
                shi.style.display = 'none';
                del_book(book_id);
            }

        }

    }

    function add_book(id){
        $.ajax({
            type:'get',
            url:'/bookmarkers/'+id,
            dataType : 'json',
            success:function(data){
                if(data.status){
                    toastr.success(data.info);
                }else{
                    toastr.error(data.info, 'WARING!!!!!!:');
                }
            },
            error:function(data){
                alert('AJAX操作失败');
            }
        })
    }

    function del_book(id){
        $.ajax({
            type:'delete',
            url:'/bookmarkers/'+id+'.html',
            dataType : 'json',
            success:function(data){
                if(data.status){
                    toastr.success(data.info);
                }else{
                    toastr.error(data.info, 'WARING!!!!!!:');
                }
            },
            error:function(data){
                alert('AJAX操作失败');
            }
        })
    }


</script>
{/block}